﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommandLine
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("  Version: v0.1");
                Console.WriteLine("  -h for help");
                return;
            }
            if (args[0][0] == '-')
            {
                if (args[0].Length < 2)
                {
                    Console.WriteLine("  No such command, sorry.");
                    return;
                }
                switch (args[0][1])
                {
                    case 'h':
                        Console.WriteLine("  codecompare file1 file2: compare the file1 with file2.");
                        Console.WriteLine("  codecompare directory: compare all the files in the directory.");
                        break;
                    default:
                        break;
                }

                return;
            }

            if (args.Length == 2)           // compare two files;
            {
                StringBuilder output = new StringBuilder();
                List<Degree> degList = CompareManager.Compare(args[0], args[1], ref output);
                Console.WriteLine(output.ToString());
                Console.WriteLine();
                foreach (var dl in degList)
                {
                    Console.WriteLine("{0}, {1}, {2}", dl.deg1, dl.deg2, dl.degMixed);
                }
            } else if (args.Length == 1)    // compare files in the directory
            {
                FolderComparer fc = new FolderComparer(args[0]);
                List<string> pathList = fc.GetCodeFiles();
                int cnt = 0;

                for (int i = 0; i < pathList.Count; i++)
                {
                    for (int j = i + 1; j < pathList.Count; j++)
                    {
                        StringBuilder output = new StringBuilder();
                        CompareManager.Compare(pathList[i], pathList[j], ref output);
                        cnt++;
                        Console.WriteLine(cnt);
                    }
                }
            }

            Console.ReadLine();
        }
    }
}
